package com.wyj.utils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.wyj.common.LogPortal;
import com.wyj.task.HappyRankInfoTask;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class HappyRankTaskUtil {

    private static final int POOL_SIZE = 10000;

    private static final ThreadFactory factory =
            new ThreadFactoryBuilder().setNameFormat("VoucherOrder-Thread-%d").build();

    private static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            5, 5, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>(POOL_SIZE), factory);


    public static void submitTask(String uuid,int points) {
        try {
            HappyRankInfoTask rankInfoTask = new HappyRankInfoTask(uuid, points);
            threadPoolExecutor.submit(rankInfoTask);
        } catch (Exception e) {
            LogPortal.error(HappyRankTaskUtil.class.getSimpleName() + " 执行任务异常", e);
        }
    }

}
